<?php

function JSString($str) {
	if (is_string($str))
		$str = CStr($str);
	
	$chars = &$str->AllCharacters();
	$s = '';
	while (($c = $chars->NextChar()) !== null) {
		if ($c < 128) {
			$c = addcslashes(chr($c));
			$s .= $c;
		} else
			$s .= "\\u$c";
	}
	
	return $s;
}

?>